const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {
	cssLoaders,
} = require('./config.css')

const {
	PATHS,
} = require('./utils')

const isProduction = process.env.NODE_ENV === 'production'

module.exports = {
	rules: [
		// {
		// 	// 编译前通过eslint检查代码 (注释掉即可取消eslint检测)
		// 	test: /\.js?$/,
		// 	enforce: "pre",
		// 	include: PATHS.src,
		// 	loader: "eslint-loader",
		// }, 

		{
			test: /\.vue$/,
			use: [{
				loader: 'vue-loader',
				options: {
					loaders: cssLoaders({
						sourceMap: isProduction,
						extract: isProduction,
					}),
				}
			}]
		}, {
			test: /\.js?$/,
			include: PATHS.src,
			use: [{
				loader: 'babel-loader',
				options: {
					presets: ['env'],
					compact: false,
				},
			}]
		}, {
			test: /\.css$/,
			use: [
				MiniCssExtractPlugin.loader,
				'css-loader'
			],
		}, {
			test: /\.sass$/,
			use: [
				MiniCssExtractPlugin.loader,
				'css-loader',
				'postcss-loader',
				'sass-loader',
			],
		}, {
			test: /\.less$/,
			use: [
				MiniCssExtractPlugin.loader,
				'css-loader',
				'postcss-loader',
				'less-loader',
			],
		}, {
			test: /\.html$/,
			use: ['html-loader'],
		}, {
			// 文件解析
			test: /\.(eot|woff|svg|ttf|woff2|appcache|mp3|mp4|pdf)(\?|$)/,
			use: [{
				loader: "file-loader",
				options: {
					name: PATHS.assets('css/[name].[hash:6].[ext]'),
				},
			}]
		}, {
			// 图片解析
			test: /\.(png|jpg|gif)$/,
			use: [{
				loader: "url-loader",
				options: {
					limit: 8192,
					name: PATHS.assets('css/[name].[hash:6].[ext]'),
				},
			}]
		}, {
			test: /\.xml$/,
			use: ['xml-loader'],
		}
	],
}